// pages/index/index_add/index_add.js
const $api = require("../../../api/index").API
const $upload = require("../../../api/upload").API


Page({
    data: {
        fileList: [],
        circle_files:[],
        txt:"",
    },
    onLoad() {
        var t = this
    },
    upload(e){
      var t = this
      var fileList = t.data.fileList
      fileList = fileList.concat(fileList)
      t.setData({
        fileList:e.detail.file
      })
    },
    imgdelete(e){
      console.log(e.detail.index)
      var t = this
      var fileList = t.data.fileList
      fileList.splice(e.detail.index,1)
      t.setData({
        fileList:fileList
      })
    },
    // 发布动态
    saveDynamic() {
      var t = this
      $upload.uploadQiniu(t.data.fileList).then(res=>{
        var data = {
          member_id:wx.getStorageSync('memberinfo').member_id,
          member_type:wx.getStorageSync('memberinfo').member_type,
          institution_id:wx.getStorageSync('TeacherClassinfo').institution_id,
          grade_id:wx.getStorageSync('TeacherClassinfo').grade_id,
          class_id:wx.getStorageSync('TeacherClassinfo').class_id,
          circle_content:t.data.txt,
          circle_open:true,
          circle_address:"",
          circle_longitude:"",
          circle_latitude:"",
          circle_type:"image",
          circle_files:res
        }
        $api.saveDynamic(data).then(res=>{
          console.log(res)
          wx.navigateBack({
            delta: 1,
          })
        })
      })
      
    },
    settxt(e){
      var t = this
      t.setData({
        txt:e.detail
      })
    },
    beforechoose(e){
      console.log(e)
    },
})
